<?php

namespace App\Http\Controllers;


use App\Service\Sms;
use Illuminate\Http\Request;

class SmsController extends Controller
{
    public function send(Request $request)
    {
        $this->validate($request, [
            'phone' => 'required'
        ]);

        $phone = $request->get('phone');
        $code = Sms::generate($phone);
        $res = Sms::send($phone, $code);

        if ($res) {
            $data = [
                'code' => 0,
                'msg' => 'success'
            ];
        } else {
            $data = [
                'code' => 40001,
                'msg' => 'error'
            ];
        }
        return response()->json($data);

    }
}
